<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        #box{
            width: 200px;
            height: 50px;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <input type="text" id = "num1">
    <input type="text" id = "num2">
    <button onclick="sum(1)">加</button>
    <button onclick="sum(2)">减</button>
    <button onclick="sum(3)">乘</button>
    <button onclick="sum(4)">除</button>
    <hr>
    <div id="box"></div>
    <script>
        var sum = function(action){
            var num1 = document.getElementById('num1');
            var num2 = document.getElementById('num2');
            switch(action){
                case 1:  var sum = Number(num1.value)+ Number(num2.value);break;
                case 2:  var sum = Number(num1.value)- Number(num2.value);break;
                case 3:  var sum = Number(num1.value)* Number(num2.value);break;
                case 4:  var sum = Number(num1.value)/ Number(num2.value);break;
            }
            document.getElementById('box').innerHTML = sum.toFixed(2); 
        }
    </script>
</body>
</html>